package com.flower.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.flower.pojo.User;
import com.flower.service.IOrderService;
import com.flower.service.IProductService;

/**
 *	会员：个人中心模块
 */
@Controller
public class HomeController {
	@Resource(name = "orderService")
	private IOrderService iOrderService;
	@Resource(name = "productService")
    private IProductService iProductService;
	
	
	/**
	 * 个人中心页面展示已付账的订单
	 */
	@RequestMapping("/findOrder.do")
	public String findOrder(HttpServletRequest request){
		User user = (User) request.getSession().getAttribute("USER");
		List<Map<String, Object>> orders = iOrderService.findOrdersByUId(user.getUid());
		System.out.println(user.getUid() + " " + orders);
		/*List<Order> orders = iOrderService.findOrder(user.getUid(), 1);
		List<Product> products = new ArrayList<Product>();
		for(int i=0; i<orders.size(); i++){
			Product product = iProductService.findProductByPid(orders.get(i).getPid());
			products.add(product);
		}
		request.getSession().setAttribute("PRODUCTS", products);*/
		
		request.getSession().setAttribute("orders", orders);

		return "redirect:/my_home.jsp";
	}
	
}
